home *** CD-ROM | disk | FTP | other *** search
/ CD Exchange / CD Exchange - Volume 1.iso / d.t.p / utils / others / pcal / pcalinit.ps < prev    next >
Text File  |  1992-02-21  |  14KB  |  602 lines

  1. % pcalinit.ps - provides the PostScript routines for pcal.c
  2. %
  3. % 4.3    modified by Andrew Rogers:
  4. %
  5. %    removed definitions of dategray and fillgray; handled instead by
  6. %    Pcal itself (may be selected by user via -s flag)
  7. %
  8. %    enlarge dates in small and medium calendars; enlarge title and
  9. %    weekday names in medium calendars
  10. %
  11. % 4.2    modified by Andrew Rogers:
  12. %
  13. %    support -[kK] options to reposition small calendars
  14. %
  15. %    use same font size for "Notes" as for weekday names; delete heading
  16. %    from notes box if null
  17. %
  18. %    move definition of notesfontsize to Pcal proper; tweak some of the
  19. %    routines to take variable font size into account
  20. %
  21. %    add support for printing notes in any blank box on calendar and
  22. %    suppressing small calendars
  23. %
  24. % 4.1    modified by Andrew Rogers:
  25. %
  26. %    support -G option (cf. prtday) to print "gray" dates as filled
  27. %    outlines
  28. %
  29. % 4.0    modified by Andrew Rogers:
  30. %
  31. %    support -w ("whole year") option - cf. printmonth_[pl], startpage
  32. %    moved all the calendar calculations to pcal.c and moonphas.c (q.v.)
  33. %
  34. %    support -B option (leave unused boxes blank)
  35. %
  36. %    support -O option (print "gray" numbers as outlines)
  37. %
  38. %    revised several of the basic routines and added some others; dates,
  39. %    moons, text, Julian days are now relative to upper-left corner of box
  40. %
  41. %    enlarged title and dates in small calendars
  42. %
  43. % 3.0    modified by Andrew Rogers:
  44. %
  45. %    added xsval, ysval, xtval, ytval for scaling and translation
  46. %    as per Ed Hand
  47. %
  48. %    added day-of-year support (-j, -J flags)
  49. %
  50. % 2.6    * no modifications *
  51. %
  52. % 2.5    modified by Joe Brownlee:
  53. %
  54. %    made day numbers smaller, providing more room for event text
  55. %    repositioned event text and moons accordingly
  56. %    added support for variable first day of week
  57. %
  58. % 2.4    * no modifications *
  59. %
  60. % 2.3    modified by Jamie Zawinski <jwz@lucid.com>:
  61. %
  62. %    merged in moon routines (originally by Mark Hanson)
  63. %
  64. % 2.2    modified by Joe Brownlee:
  65. %
  66. %    add "notetext" to print notes in unused calendar box
  67. %
  68. % 2.1    modified by Mark Kantrowitz:
  69. %
  70. %    use symbolic names instead of magic numbers throughout
  71. %    support -L, -C, -R, -n options (all new)
  72. %    print holiday text in otherwise-wasted space next to date
  73. %    use larger text for dates in large calendars
  74. %
  75. % 2.0    modified by Andrew W. Rogers:
  76. %
  77. %    skip printing days of week on small calendars
  78. %    center month and year at top of calendar
  79. %    use correct algorithm for leap year calculation
  80. %    get month and day names from main program
  81. %    use table to determine color (black/gray) of weekdays and holidays
  82. %    use hanging indent to print continued text lines
  83.  
  84. /SM 0 def                % definitions for calendar sizes
  85. /MED 1 def
  86. /LG 2 def
  87.  
  88. /titlefontsize   [ 60 52 48 ] def    % font sizes for SM/MED/LG calendars
  89. /datefontsize    [ 60 48 25 ] def
  90. /weekdayfontsize [  0 28 12 ] def
  91. /footfontsize 12 def
  92.  
  93. /titlepos [ 19 43 25 ] def        % Y-offset (SM/MED/LG) of month/year title
  94. /Y0 35 def                % Y-coordinate of calendar grid origin
  95.  
  96. /daywidth 100 def            % dimensions of grid boxes
  97. /dayheight 80 def
  98. /gridwidth daywidth 7 mul def
  99. /gridheight dayheight 6 mul def
  100. /negdaywidth daywidth neg def
  101. /negdayheight dayheight neg def
  102. /neggridwidth gridwidth neg def
  103. /neggridheight gridheight neg def
  104.  
  105. /gridlinewidth 1.0 def            % width of grid lines
  106. /charlinewidth 0.1 def            % width of outline characters
  107. /moonlinewidth 0.1 def            % width of moon icon line
  108.  
  109. /hangingindent (   ) def        % for indenting continued text lines
  110.  
  111. %
  112. % Utility functions:
  113. %
  114.  
  115.  
  116. /center {        % print string centered in given width
  117.     /width exch def
  118.     /str exch def
  119.     width str stringwidth pop sub 2 div 0 rmoveto str show
  120. } def
  121.  
  122.  
  123. /strcat {        % concatenate two strings
  124.     2 copy
  125.     length exch length
  126.     dup 3 -1 roll add
  127.     string
  128.     dup 0 6 -1 roll putinterval
  129.     dup 3 -1 roll 4 -1 roll putinterval
  130. } def
  131.  
  132.  
  133. /prtday {        % print date in black, gray, outline, or filled outline
  134.     day 3 string cvs                % convert to string
  135.     color (black) eq {
  136.         show
  137.     } if
  138.     color (gray) eq {
  139.         dategray setgray show
  140.     } if
  141.     color (outline) eq {
  142.         true charpath stroke
  143.     } if
  144.     color (outline_gray) eq {
  145.         true charpath
  146.         gsave dategray setgray fill grestore
  147.         stroke
  148.     } if
  149. } def
  150.  
  151.  
  152. /nextbox {        % go to next column or start of next row
  153.     day startbox add 7 mod 0 eq                % end of week?
  154.         { neggridwidth daywidth add negdayheight rmoveto }  % next row
  155.         { daywidth 0 rmoveto }                    % next col
  156.     ifelse
  157. } def
  158.  
  159.  
  160. /boxpos {        % push coords of upper-left corner of box <arg> (0..41)
  161.     dup 7 mod daywidth mul                    % x-coord
  162.     exch 7 idiv negdayheight mul Y0 add            % y-coord
  163. } def
  164.  
  165.  
  166. /datepos {        % push coords of upper-left corner of box for day <arg>
  167.     startbox add 1 sub dup 7 mod daywidth mul        % x-coord
  168.     exch 7 idiv negdayheight mul Y0 add            % y-coord
  169. } def
  170.     
  171.  
  172. %
  173. % Functions for drawing parts of calendar:
  174. %
  175.  
  176.  
  177. /drawtitle {        % draw month and year title
  178.     titlefont findfont titlefontsize calsize get scalefont setfont
  179.     /month_name month_names month 1 sub get def
  180.     /yearstring year 10 string cvs def
  181.     0 Y0 titlepos calsize get add moveto
  182.     month_name (  ) strcat yearstring strcat gridwidth center
  183. } def
  184.  
  185.  
  186. /drawdaynames {        % draw day names above respective columns
  187.     dayfont findfont weekdayfontsize calsize get scalefont setfont
  188.     0 1 6 {
  189.         /i exch def
  190.         i daywidth mul Y0 5 add moveto
  191.         day_names i get
  192.         daywidth center
  193.     } for
  194. } def
  195.  
  196.  
  197. /drawgrid {        % draw the grid for the calendar
  198.     gridlinewidth setlinewidth
  199.     0 daywidth gridwidth {            % vertical lines
  200.         Y0 moveto
  201.         0 neggridheight rlineto
  202.         stroke
  203.     } for
  204.     0 negdayheight neggridheight {        % horizontal lines
  205.         0 exch Y0 add moveto
  206.         gridwidth 0 rlineto
  207.         stroke
  208.     } for
  209. } def
  210.  
  211.  
  212. /drawnums {        % place day numbers on calendar
  213.     dayfont findfont datefontsize calsize get scalefont setfont
  214.     /fontdiff datefontsize calsize get datefontsize LG get sub def
  215.     charlinewidth setlinewidth
  216.     1 datepos 20 fontdiff add sub exch 5 add exch moveto
  217.  
  218.     1 1 ndays {
  219.         /day exch def
  220.         /color (black) def
  221.         calsize SM ne {        % select alternate color
  222.             /gray day_gray day startbox add 1 sub 7 mod get def
  223.             holidays { day eq { /gray holiday_gray def } if } forall
  224.             gray {
  225.                 /color logical_gray def
  226.             } if
  227.         } if
  228.         gsave
  229.         prtday
  230.         grestore
  231.         nextbox
  232.     } for
  233. } def
  234.  
  235.  
  236. /drawjnums {        % place day-of-year numbers on calendar
  237.     notesfont findfont notesfontsize scalefont setfont
  238.     1 datepos dayheight 3 sub sub exch daywidth 3 sub add exch moveto
  239.  
  240.     1 1 ndays {
  241.         /day exch def
  242.         /jday jdstart day add 1 sub def
  243.         /str jday 3 string cvs def
  244.         julian-dates true eq {        % print days left in year?
  245.             /str str ( \050) strcat yearlen jday sub 3 string cvs
  246.                 strcat (\051) strcat def
  247.         } if
  248.         gsave
  249.         str dup stringwidth pop 0 exch sub 0 rmoveto show
  250.         grestore
  251.         nextbox
  252.     } for
  253. } def
  254.  
  255.  
  256. /fillboxes {        % used by drawfill to generate group of fill squares
  257.     /last exch def        % last box to fill (41 = lower right box)
  258.     /first exch def        % first box to fill (0 = upper left box)
  259.  
  260.     first 1 last {        % loop through range of boxes
  261.         /box exch def
  262.         /fillit true def
  263.         calsize LG eq {        % skip note and small calendar boxes
  264.             noteboxes { box eq { /fillit false def } if } forall
  265.             box prev_small_cal eq box next_small_cal eq or {
  266.                 /fillit false def
  267.             } if
  268.         } if
  269.         fillit {        % move to position and fill the box
  270.             box boxpos moveto
  271.             gsave
  272.             fillgray setgray
  273.             daywidth 0 rlineto
  274.             0 negdayheight rlineto
  275.             negdaywidth 0 rlineto
  276.             closepath fill
  277.             grestore
  278.         } if
  279.     } for
  280. } def
  281.  
  282.  
  283. /drawfill {        % generate fill squares where necessary
  284.     0 startbox 1 sub fillboxes        % fill boxes before calendar
  285.     startbox ndays add 41 fillboxes        % fill boxes after calendar
  286. } def
  287.  
  288.  
  289. /footstrings {        % print foot strings at bottom of page
  290.     titlefont findfont footfontsize scalefont setfont
  291.     /bottomrow { neggridheight 20 add } def
  292.     0 bottomrow moveto
  293.     Lfootstring show
  294.     gridwidth Rfootstring stringwidth pop sub bottomrow moveto
  295.     Rfootstring show
  296.     0 bottomrow moveto
  297.     Cfootstring gridwidth center
  298. } def
  299.  
  300.  
  301. %
  302. % Functions for printing text inside boxes:
  303. %
  304.  
  305.  
  306. /daytext {
  307.     /mytext exch def /day exch def
  308.     notesfont findfont notesfontsize scalefont setfont
  309.     day datepos datefontsize LG get notesfontsize add 2 sub sub dup
  310.     /ypos exch def exch 2 add exch moveto
  311.     currentpoint pop /LM exch def /RM LM 95 add def
  312.     showtext
  313. } def
  314.     
  315.  
  316. /holidaytext {        % print text for holiday (next to date)
  317.     notesfont findfont notesfontsize scalefont setfont
  318.     /mytext exch def /day exch def
  319.     /